package com.mapfinal.server.web;

import com.lambkit.common.util.StringUtils;
import com.mapfinal.server.MapfinalServerConsts;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * 公共拦截器
 */
public class WebInterceptor implements Interceptor {

    //private static final Log LOG = Log.getLog(CmsWebInterceptor.class);

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		// 过滤ajax
        if (null != controller.getHeader("X-Requested-With") && "XMLHttpRequest".equalsIgnoreCase(controller.getHeader("X-Requested-With"))) {
        	System.out.println("X-Requested-With: " + "/mapfinal");
        	inv.invoke();
        } else {
        	controller.set(MapfinalServerConsts.ATTR_TEMPLATE_PATH, controller.getRequest().getContextPath() + "/mapfinal");
            // 菜单
            controller.set("curl", StringUtils.urlDecode(controller.getRequest().getRequestURI()));
    		inv.invoke();
        }
	}
}
